module.exports = app => {
    const express = require('express');
    const router = express.Router({
        mergeParams: true
    });
    const My = require('../model/My')
    const jwt=require('jsonwebtoken')

    router.post('/my', async (req, res) => {
        const model=await My.create(req.body)
        res.send(model)
    })
    router.post('/login',async (req,res)=>{
        const {username,password}=req.body
        const user=await My.findOne({username}).select('+password')
        if (!user){
            return res.status(422).send(JSON.stringify({
                data:'用户名或密码错误',
            }))
        }else if (!require('bcrypt').compareSync(password,user.password)){
            return res.status(422).send(JSON.stringify({data:'用户名或密码错误'}))
        }else{
            res.status(200).send({
                data:'登录成功'
            })
        }
    })
    app.use('/admin/api', router)
};
